package wfw.hospital.msm.receiver;

import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import wfw.hospital.msm.utils.HttpUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author CCFu
 * @version 1.0
 * @date 2022/2/24 15:01
 */
public class Test {
    private final static String host = "https://dfsns.market.alicloudapi.com";
    private final static String path = "/data/send_sms";
    private final static String method = "POST";
    @Value("${aliyun.appcode}")
    private String appcode;
    public static void main(String[] args) {


        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + "264a2fdc699a4e51a63443766d33dbeb");
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("content", "code: "+"123456");
        bodys.put("phone_number", "15828181797");
        bodys.put("template_id", "TPL_0000");


        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            //System.out.println(response.toString());
            System.out.println(response.getEntity());
            System.out.println(response.getLocale());
            System.out.println(response.getStatusLine());
            if(response.getStatusLine().toString().contains("200")){
                System.out.println("ok");
            }
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
